package com.offcn;

import com.aliyun.oss.OSS;
import com.aliyun.oss.OSSClientBuilder;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;

/**
 * @author XingLi
 * @create 2021-03-11 19:18
 */
public class OssUpload {

    public static void main(String[] args) throws FileNotFoundException {
        String endpoint="https://oss-cn-qingdao.aliyuncs.com";
        String accessKeyId="LTAI4G7KHTJHLac78fSm6rLv";
        String accessKeySecret="NWUirbN9aztoKz0CMXayeMrPbSWPeE";

        //创建oss客户端对象
        OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret);

        //准备一个要上传的文件
        File file = new File("F:\\pic\\1.jpg");

        //创建一个输入流
        FileInputStream inputStream = new FileInputStream(file);

        //用oss客户端对象，执行文件上传
        ossClient.putObject("leyi001","pic/1001.jpg",inputStream);

        System.out.println("文件上传成功");

        try {
            inputStream.close();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
